﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<FileSharing.Models.PathInfoModel>" %>

<asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">
    File Explorer
</asp:Content>

<asp:Content ID="indexFeatured" ContentPlaceHolderID="FeaturedContent" runat="server">
    <section class="featured">
        <div class="content-wrapper">
            <hgroup class="title">
                <h1>File Explorer</h1>
                <h2>is a simple application for managing the files over HTTP</h2>
                <h3>across own devices, typically within a home or office network, that too, without any hassles of authentication or authorization.</h3>
            </hgroup>
            <p>Click on the link the the name to explore a folder or to download a file. Select multiple files to upload them to the current folder.</p>
        </div>
    </section>
</asp:Content>

<asp:Content ID="indedContent" ContentPlaceHolderID="MainContent" runat="server">
    <p>
        <%
            var values = new Dictionary<int, KeyValuePair<string, string>>();
            int indexer = 0;

            if (this.Model != null
                && !string.IsNullOrWhiteSpace(this.Model.FullPath))
            {
                string p = this.Model.FullPath;
                if (this.Model.FileType != FileSharing.Models.PathType.Unknown)
                {
                    do
                    {
                        values.Add(indexer++, new KeyValuePair<string, string>(FileSharing.Helpers.ModelHelper.GetDisplayName(p), p));

                        var parent = System.IO.Directory.GetParent(p);
                        p = parent != null ? parent.FullName : null;

                    }
                    while (p != null);
                }
                else
                {
                    values.Add(indexer++, new KeyValuePair<string, string>(FileSharing.Helpers.ModelHelper.GetDisplayName(p), p));
                }
            }
            values.Add(indexer++, new KeyValuePair<string, string>(FileSharing.Helpers.ModelHelper.GetDisplayName(""), string.Empty));
            for (int i = indexer - 1; i >= 0; i--)
            {
                var valueItem = values[i];
        %><i><%: this.Html.ActionLink(valueItem.Key, "index", new { controller = "files", path = valueItem.Value}) %></i><%
                if (i != 0)
                {
        %><b>&gt;</b><% 
                }
            }
        %>
    </p>
    <h2><%: this.Model.FileType %>: <%: FileSharing.Helpers.ModelHelper.GetDisplayName(this.Model.FullPath) %></h2>

    <h4><%: this.Model.Message %></h4>
    <% if (this.Model.Exists
           && (this.Model.FileType == FileSharing.Models.PathType.Drive || this.Model.FileType == FileSharing.Models.PathType.Directory))
       {
    %>
    <% using (this.Html.BeginForm("upload", "files", FormMethod.Post, new { enctype = "multipart/form-data" }))
       { 
    %>
    <%: this.Html.AntiForgeryToken()%>
    <%: this.Html.ValidationSummary(true)%>
    <fieldset>
        <legend>Upload a file</legend>
        <div>
            <input type="file" id="files" name="files" multiple="multiple" draggable="true" />
            <input type="submit" value="Upload" />
        </div>
        <div>
            <input type="hidden" id="targetPath" name="targetPath" value="<%:this.Model.FullPath%>" />
            <input type="checkbox" id="overwriteOriginal" name="overwriteOriginal" value="overwriteOriginal" />Overwrite
        </div>
    </fieldset>
    <% } %>
    <%
       }
    %>
    <% if (this.Model.Children != null && this.Model.Children.Count > 0)
       {
    %>
    <table>
        <tr>
            <th>No</th>
            <th>Name</th>
            <th>Type</th>
            <th>Size (bytes)</th>
            <th>Modified Time</th>
        </tr>
        <% for (int i = 0; i < this.Model.Children.Count; i++)
           {
               var item = this.Model.Children[i];
        %>
        <tr>
            <td><%:i + 1 %></td>
            <td>
                <%: this.Html.ActionLink(item.DisplayName, "index", new {controller = "files", path= item.FullPath})%>                
            </td>
            <td>
                <%: item.FileType %>
            </td>
            <td>
                <%: item.Size > 0 ? item.Size.ToString() : "" %>
            </td>
            <td>
                <%: item.ModifiedTime != default(DateTime) ? item.ModifiedTime.ToString() : ""  %>
            </td>
        </tr>
        <% } %>
    </table>
    <%
       }
    %>
</asp:Content>


<asp:Content ID="Content4" ContentPlaceHolderID="ScriptsSection" runat="server">
</asp:Content>
